import { createSlice } from "@reduxjs/toolkit";

export const progressSlice = createSlice({
    name: 'progressSlice',
    initialState: {
        uploadList: [],
        downloadList: [],
        open: false
    },
    reducers: {
        postUpload:(state, action) => {
            state.uploadList.push(action.payload)
        },
        updateUpload:(state, action) => {
            for (let index = 0; index < state.uploadList.length; index++) {
                const element = state.uploadList[index];
                if (element.id === action.payload.id) {
                    state.uploadList[index] = action.payload;
                    break;
                }
            }
        },
        setProgressOpen:(state, action) => {
            const oldState = state;
            state.open = action.payload;
        }
    }
})


export const { postUpload, updateUpload, setProgressOpen } = progressSlice.actions

export default progressSlice.reducer 
